package com.enfi.api.modules.ext.mq.factory;

import com.enfi.api.modules.ext.mq.common.MessageTypeEnum;
import com.enfi.api.modules.ext.mq.strategy.BaseStrategy;
import org.springframework.util.Assert;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author xukk
 * @date 2020/3/10
 */
public class MessageFactory {
    private static Map<MessageTypeEnum, BaseStrategy> services = new ConcurrentHashMap<MessageTypeEnum, BaseStrategy>();

    public  static BaseStrategy getByType(MessageTypeEnum messageTypeEnum){
        return services.get(messageTypeEnum);
    }

    public static void register(MessageTypeEnum messageTypeEnum,BaseStrategy baseStrategy){
        Assert.notNull(messageTypeEnum,"messageType can't be null");
        services.put(messageTypeEnum,baseStrategy);
    }
}
